package com.pktechan.api.service.impl;

import com.pktechan.api.base.BaseMapper;
import com.pktechan.api.base.BaseServiceImpl;
import com.pktechan.api.dao.CommissionGenerateFlowMapper;
import com.pktechan.api.dto.CommissionDTO;
import com.pktechan.api.entity.CommissionGenerateFlow;
import com.pktechan.api.service.CommissionGenerateFlowService;
import com.pktechan.api.vo.CommissionGenerateFlowVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("commissionGenerateFlowService")
@Transactional
public class CommissionGenerateFlowServiceImpl extends BaseServiceImpl<CommissionGenerateFlow> implements CommissionGenerateFlowService {

    @Autowired
    private CommissionGenerateFlowMapper commissionGenerateFlowMapper;

    /**
     * 由业务类实现
     *
     * @return
     */
    @Override
    public BaseMapper<CommissionGenerateFlow> getBaseMapper() {
        return commissionGenerateFlowMapper;
    }

    /**
     * 佣金生成明细列表
     *
     * @param custId
     * @return
     */
    @Override
    public List<CommissionGenerateFlowVo> getCommissionGenerateDetailsListByCustId(Integer custId) {
        return commissionGenerateFlowMapper.getCommissionGenerateDetailsListByCustId(custId);
    }

    /**
     * 根据订单ID查询一级推荐人佣金汇总
     *
     * @param tradeOrderId
     * @param commissionGeneration
     * @return
     */
    @Override
    public CommissionDTO getTotalCommissionByTradeOrderId(Integer tradeOrderId, Integer commissionGeneration) {
        CommissionGenerateFlow commissionGenerateFlow = new CommissionGenerateFlow();
        commissionGenerateFlow.setTradeOrderId(tradeOrderId);
        commissionGenerateFlow.setCommissionGeneration(commissionGeneration);
        return commissionGenerateFlowMapper.getTotalCommissionByTradeOrderId(commissionGenerateFlow);
    }

    /**
     * 根据订单ID与佣金代数生成佣金流水
     *
     * @param tradeOrderId
     * @param commissionGeneration
     */
    @Override
    public void saveCommissionGenerateFlowByTradeOrderId(Integer tradeOrderId, Integer commissionGeneration) {
        CommissionGenerateFlow commissionGenerateFlow = new CommissionGenerateFlow();
        commissionGenerateFlow.setTradeOrderId(tradeOrderId);
        commissionGenerateFlow.setCommissionGeneration(commissionGeneration);
        commissionGenerateFlowMapper.saveCommissionGenerateFlowByTradeOrderId(commissionGenerateFlow);
    }

    /**
     * 根据订单ID与佣金代数查询已生成的佣金流水
     *
     * @param tradeOrderId
     * @param commissionGeneration
     * @return
     */
    @Override
    public List<CommissionGenerateFlow> getCommissionGenerateFlowListByTradeOrderId(Integer tradeOrderId, Integer commissionGeneration) {
        CommissionGenerateFlow commissionGenerateFlow = new CommissionGenerateFlow();
        commissionGenerateFlow.setTradeOrderId(tradeOrderId);
        commissionGenerateFlow.setCommissionGeneration(commissionGeneration);
        return commissionGenerateFlowMapper.getCommissionGenerateFlowListByTradeOrderId(commissionGenerateFlow);
    }
}
